package com.campus_information_portal.controller;

import com.campus_information_portal.entity.Student;
import com.campus_information_portal.service.StudentService;
import com.campus_information_portal.util.Message;
import com.itextpdf.text.DocumentException;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.net.UnknownHostException;

/**
 * @author 20155883 万珊
 * @description 学生控制层
 * @project_name StudentController
 * @package com.campus_information_portal.controller
 * @create 2018-05-24 10:00
 **/
@Controller
@RequestMapping("/student")
@ResponseBody
@CrossOrigin(origins = "*")
public class StudentController {
    @Autowired
    private StudentService studentService;

    /**
     * @param stuNum
     * @Description 根据Student表中的学生学号查询学生个人信息
     * @author 20155883 万珊
     * @methodName queryStudentByStuNum
     * @returnType  Message
     * @create 2018/4/26 8:45
     **/
    @RequestMapping(value = "/queryStudentByStuNum",method = RequestMethod.GET)
    public Message queryStudentByStuNum(@Param("stuNum")int stuNum){
        return studentService.queryStudentByStuNum(stuNum);
    }

    /**
     * @param stuNum
     * @Description 查找学号是否存在
     * @author 20155880 房雁颖
     * @methodName queryStuNum
     * @returnType Message
     * @create 2018/4/26 15:26
     **/
    @RequestMapping(value = "/queryStuNum",method = RequestMethod.GET)
    public Message queryStuNum(@Param("stuNum")int stuNum){
        return studentService.queryStuNum(stuNum);
    }

    /**
     * @param student
     * @Description 增加一个学生（学号+密码）
     * @author 20155880 房雁颖
     * @methodName addStudent
     * @returnType Message
     * @create 2018/4/26 15:26
     **/
    @RequestMapping(value = "/addStudent",method = RequestMethod.POST)
    public Message addStudent(@RequestBody Student student){
        return studentService.addStudent(student);
    }

    /**
     * @param stuNum
     * @Description 删除学生信息表【警告！这是真删！无特殊情况不可调用此接口！】
     * @author 20155883 万珊
     * @methodName deleteStudent
     * @returnType Message
     * @create 2018/4/26 15:26
     **/
    @RequestMapping(value = "/deleteStudent",method = RequestMethod.GET)
    public Message deleteStudent(@Param("stuNum")int stuNum){
        return studentService.deleteStudent(stuNum);
    }

    /**
     * @Description 查询全部学生
     * @author 20155883 万珊
     * @methodName queryStudent
     * @returnType Message
     * @create 2018/4/26 8:45
     **/
    @RequestMapping(value = "/queryStudent",method = RequestMethod.GET)
    public Message queryStudent(){
        return studentService.queryStudent();
    }

    /**
     * @param student
     * @Description 修改学生信息表（姓名，性别，身份证，出生年月，民族，电话，籍贯）
     * @author 20155880 房雁颖
     * @methodName updateStudent
     * @returnType Message
     * @create 2018/4/26 15:26
     **/
    @RequestMapping(value = "/updateStudent",method = RequestMethod.POST)
    public Message updateStudent(@RequestBody Student student){
        return studentService.updateStudent(student);
    }

    /**
     * @Description 下载生成学生信息表
     * @author 20155883 万珊
     * @methodName download
     * @param
     * @returnType Message
     * @create 2018/5/21 17:27
     **/
    @RequestMapping(value = "/download",method = RequestMethod.GET)
    public Message download(@Param("stuNum")String stuNum,
                            @Param("stuName")String stuName,
                            @Param("stuSex")String stuSex,
                            @Param("stuIdcardNum")String stuIdcardNum,
                            @Param("stuBirthday")String stuBirthday,
                            @Param("stuNation")String stuNation,
                            @Param("stuPoli")String stuPoli,
                            @Param("stuPhone")String stuPhone,
                            @Param("stuNativeplace")String stuNativeplace,
                            @Param("stuGrade")String stuGrade,
                            @Param("cet46Grade")String cet46Grade,
                            @Param("academyName")String academyName
                            ) throws IOException, DocumentException {
        System.out.println(stuNum);
        System.out.println(stuName);
        System.out.println(stuSex);
        System.out.println(stuIdcardNum);
        System.out.println(stuBirthday);
        System.out.println(stuNation);
        System.out.println(stuPoli);
        System.out.println(stuPhone);
        System.out.println(stuNativeplace);
        System.out.println(stuGrade);
        System.out.println(cet46Grade);
        System.out.println(academyName);

        return studentService.download(stuNum,stuName,stuSex,stuIdcardNum,stuBirthday,stuNation,stuPoli,stuPhone,stuNativeplace,stuGrade,cet46Grade,academyName);
    }
}
